package com.util;

import java.io.*;
import java.nio.charset.Charset;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * @author: cxt
 * @time: 2021/3/24
 * 使用java在不解压zip文件时候读取里面的内容
 */
public class RedZip {
    public static void main(String[] args) throws IOException {

        //获取文件输入流
        FileInputStream input = new FileInputStream("E:\\111w.zip");
        ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(input), Charset.forName("GBK"));
        ZipEntry ze = null;
        //循环遍历
        while ((ze = zipInputStream.getNextEntry()) != null) {
            System.out.println("文件名：" + ze.getName() + " 文件大小：" + ze.getSize() + " bytes");
            System.out.println("文件内容：");
            //读取
            BufferedReader br = new BufferedReader(new InputStreamReader(zipInputStream, Charset.forName("GBK")));
            String line;
            //内容不为空，输出
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        }
        //一定记得关闭流
        zipInputStream.closeEntry();
        input.close();
    }
}
